﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace TreasureHunter
{
    public class Board
    {
        Form1 form;
        public Square[,] BoardGrid;
        private List<Square> defaultCards = new List<Square>();
        public const int BoardSize = 7;

        public HeapOfSquares AllSquares;

        public Board(Form1 form)
        {
            this.form = form;
            BoardGrid = new Square[BoardSize, BoardSize];
            AllSquares = new HeapOfSquares(this);
            Reset();
            this.form.pbPlayableSquare.Image = AllSquares.PlayableSquare.Texture;
        }

        /// <summary>
        /// Draws the board
        /// </summary>
        /// <param name="e"></param>
        public void Draw(PaintEventArgs e)
        {
            for (int x = 0; x < BoardSize; x++)
            {
                for (int y = 0; y < BoardSize; y++)
                {
                    if(BoardGrid[x,y] != null)
                        BoardGrid[x, y].Draw(e);
                }
            }
        }

        /// <summary>
        /// Resets the board, generating new cards and placing them on the board.
        /// </summary>
        public void Reset()
        {
            this.AllSquares.FillBoardWithPieces();
            
        }

        /// <summary>
        /// Places the default/fixed cards on the board. These cards are never allowed to change.
        /// </summary>
        private void PlaceDefaultCards()
        {
            foreach (Square fixedCard in this.defaultCards)
                this.BoardGrid[fixedCard.X, fixedCard.Y] = fixedCard;
        }

        
        
        /// <summary>
        /// Places a card on the board
        /// </summary>
        /// <param name="card">Card to be placed.</param>
        /// <param name="xIndex">X-index in the board-grid where the card is placed.</param>
        /// <param name="yIndex">Y-index in the board-grid where the card is placed.</param>
        public void PlaceCardOnBoard(Square card, int xIndex, int yIndex)
        {
            this.BoardGrid[xIndex, yIndex] = card;
        }

        
    }
}
